package com.elegantmall.service;

import cn.hutool.jwt.JWT;
import com.elegantmall.dao.AdminDao;
import com.elegantmall.pojo.AdminPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(rollbackFor = Exception.class)
public class AdminServiceImpl {
    @Autowired
    AdminDao adminDao;

    public Boolean login(String adminname,String password){
        AdminPojo adminPojo = adminDao.selectById(adminname);
        if(adminPojo == null){
            return false;
        }
        else if(!adminPojo.getPassword().equals(password)){
            return false;
        }
        else{

            return true;
        }
    }
    public String register(String adminname,String password,String nickname){
        AdminPojo adminPojo = adminDao.selectById(adminname);
        if(adminPojo !=null){
            return "用户名已被注册";
        }
        else{
            AdminPojo adminPojo2 = new AdminPojo(adminname,password,nickname);
            adminDao.insert(adminPojo2);
            return "注册成功";
        }
    }
//    //添加一个管理员
//    public void addAdmin(String adminName,String password,String nickName){
//        adminDao.insert(new AdminPojo(adminName,password,nickName));
//    }
//
//
//    public AdminPojo getAdminByName(String adminName){
//        return adminDao.selectOne(new QueryWrapper<AdminPojo>().like("admin_name",adminName));
//    }
//    public void deleteAdminById(int adminId){
//        adminDao.deleteById(adminId);
//    }
//
//    public void updateAdminById(String adminName,String password,String nickName){
//
//        adminDao.update(new AdminPojo(adminName,password,nickName),
//                new QueryWrapper<AdminPojo>().eq("adminName",adminName));
//    }
}
